/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package tabelmodel;

import java.util.ArrayList;
import java.util.List;
import javax.swing.table.AbstractTableModel;
import model.Nota;

/**
 *
 * @author tashiba
 */
public class NotaTableModel extends AbstractTableModel {

    private List<Nota> not = new ArrayList<Nota>();

    public NotaTableModel(List<Nota> nota) {
        this.not = nota;
    }

    public void deleteNota(int row) {
        not.remove(row);
        fireTableRowsDeleted(row, row);
    }

    public void updateNota(int row, Nota nota) {
        not.set(row, nota);
        fireTableRowsUpdated(row, row);
    }

    public void addNota(Nota nota) {
        not.add(nota);
        fireTableRowsInserted(getRowCount() - 1, getColumnCount() - 1);
    }

    @Override
    public int getRowCount() {
        return not.size();
    }

    @Override
    public int getColumnCount() {
        return 4;
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        Nota b = not.get(rowIndex);
        switch (columnIndex) {
             case 0:
                return b.getWaktu();
            case 1:
                return b.getIdNota();
            case 2:
                return b.getPembeli().getNoMeja() + " " + b.getPembeli().getNamaPembeli();
            case 3:
                return b.getPegawai().getIdPegawai() + " " + b.getPegawai().getNamaPegawai();

            default:
                return "";
        }
    }

    @Override
    public String getColumnName(int column) {
        switch (column) {
             case 0:
                return "Waktu";
            case 1:
                return "No. Nota";
            case 2:
                return "Pembeli";
            case 3:
                return "Pegawai";
            default:
                return "";
        }
    }
}

